#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<string>

using namespace std;

class Solution {
public:
    string convert(string s, int numRows) {
        int m = s.size();
        vector<string> temp(numRows, string(m / 2, '0'));
        int index = 0;
        int i = 0, j = 0;
        while (i == 0 && j < m / 2 && index < m)
        {
            for (i = 0; i < numRows && index < m; i++)
            {
                temp[i][j] = s[index++];
            }
            i--, j++;
            while (i > 0 && j < m / 2 && index < m)
            {
                temp[i][j] = s[index++];
                i--;
                j++;
            }
        }
        int n = j;
        string ans;
        for (i = 0; i < numRows; i++)
        {
            for (j = 0; j <= n; j++)
            {
                if (temp[i][j] != '0')
                {
                    ans.push_back(temp[i][j]);
                }
            }
        }
        return ans;

    }
};


int main()
{
    Solution S;
    string str = "PAYPALISHIRING";
    S.convert(str, 3);
    return 0;
}